<div id="group_share_weibo">
  <!-- <div><a href="javascript:;" onclick="share_weibo_tab('tab_myweibo')">我的微博</a> 
  <a href="javascript:;" onclick="share_weibo_tab('tab_mygroup')">我的群组</a></div> -->
  <form action="{:U('home/Widget/doShare')}" method="post" id="transpondForm">
	<div class="tab_mygroup" style="display:none;">
		<select name="gid">		
    	    <volist name="all_my_app" id="vo">
    	    	<if condition="$vo['id'] neq $gid"><option value="{$vo['id']}">{$vo.name}</option></if>
        	</volist>
		</select>
	</div>

	<div style="width:350px; text-align:left">
		<div  style="padding:10px">
		<span class="right" id="transpond_count" style="color:#008800">还可以输入140个汉字</span>
		</div>	
		<div style="padding:0 10px">
		<textarea id="transpond_content_{$data.weibo_id}" name="content" 
		style="font-family: Tahoma,宋体; overflow: hidden; border: 1px solid #ccc; background-color:#F8F8F8; word-wrap: break-word; font-size: 12px; line-height: 18px; height: 65px; width:328px;"
		><php>
		  if ($data['transponInfo']) {
		</php>//@{$data.transponInfo.uid|getUserName}:{$data.transponInfo.content}<php>
			} else {
		</php>//@{$data.uid|getUserName}:{$data.content}<php>
			}
		</php> [原文地址：{:getShortUrl(U('group/Group/detail',array('gid'=>$data['gid'], 'id'=>$data['weibo_id'])))} ]</textarea>
		</div>
		<div style="margin:0 0 0 12px;"> <span>添加：</span>
			<a href="javascript:void(0)" target_set="transpond_content_{$data.weibo_id}" onclick="ui.emotions(this);" class="a52"><img class="icon_add_face_d" src="__THEME__/images/zw_img.gif" />表情</a>
		</div>

		<div class="tab_myweibo">
		      <php>if ($data['transponInfo']['type'] == 1) {</php>
		      	<input type="hidden" name="type" value="1" />
		      	<input type="hidden" name="typedata" value="{$data['transponInfo']['type_data']['picurl']}" />
		      <php>} else if ($data['type'] == 1) {</php>
		      	<input type="hidden" name="type" value="1" />
		      	<input type="hidden" name="typedata" value="{$data['type_data']['picurl']}" />
		      <php>}</php>
		</div>

		<!-- <div class="tab_mygroup" style="display:none;">
			<div style="padding:20px 10px 0 10px;">
			<php>if($data['transpond_id']){</php>
				<space uid="data.transponInfo.uid" class="fn" target="_blank">@{uname}</space>:{$data.transponInfo.content|keyWordFilter|format}
			<php>}else{</php>
				<space uid="data.uid" class="fn" target="_blank">@{uname}</space>:{$data.content|keyWordFilter|format}
			<php>}</php>
			</div>
			<php>if($data['transpond_id']){</php>
			  <input type="hidden" name="transpond_id" value="{$data.transpond_id}" />
			<php>}else{</php>
			  <input type="hidden" name="transpond_id" value="{$data.weibo_id}" />
			<php>}</php>
		</div> -->

		<div class="answers right">
			<input type="button" onclick="dotranspond()" id="transpond_button" class="btn_b right" value="确定">
		</div>
	</div>
  </form>
</div>

<script>
$(document).ready(function(){
	var content_handle = "transpond_content_{$data.weibo_id}";
	var content_jquery_handle = $('#'+content_handle);
	var Interval;

	var default_transpond_string = "分享微博 [原文地址：{:getShortUrl(U('group/Group/detail',array('gid'=>$data['gid'], 'id'=>$data['weibo_id'])))} ]";

	content_jquery_handle.keypress(function(event){
		var key = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
        if (key == 27) {
        	clearInterval(Interval);
        }
		checkTranspondLength(content_jquery_handle,140);
	}).focus(function(){
	    if(content_jquery_handle.val() == default_transpond_string) {
	        content_jquery_handle.val('');
	        checkTranspondLength(content_jquery_handle,140);
	    }
	    //微博字数监控
		clearInterval(Interval);
	    Interval = setInterval(function(){
	    	checkTranspondLength(content_jquery_handle,140);
		},300);
	}).blur(function(){
		clearInterval(Interval);
	    if(content_jquery_handle.val() == '') {
	        content_jquery_handle.val(default_transpond_string);
	        checkTranspondLength(content_jquery_handle,140);
	    }
	});
	
	if (content_jquery_handle.val() == '') {
		content_jquery_handle.val(default_transpond_string);
        checkTranspondLength(content_jquery_handle,140);
	}else {
		var textArea = document.getElementById('transpond_content_{$data.weibo_id}');
	    if (document.selection) { //IE
	         var rng = textArea.createTextRange();
	         rng.collapse(true);
	         rng.moveStart("character",0)
	    }else if (textArea.selectionStart || (textArea.selectionStart == '0')) { // Mozilla/Netscape…
	        textArea.selectionStart = 0;
	        textArea.selectionEnd = 0;
	    }
		checkTranspondLength(content_jquery_handle,140);
		textArea.focus();
	}

	shortcut('ctrl+return',	function(){dotranspond();clearInterval(Interval);},{'target':content_handle});

	var url = "{:U('home/User/searchTips')}";
	userAutoTips({id:'transpond_content_<?php echo $data['weibo_id']; ?>', url:url});
});

// 标签切换
/*var share_weibo_tab = function(tab_name)
{
	var myweibo_content = '<php>if($data['transponInfo']){
						   	echo '//@' . getUserName($data['transponInfo']['uid']) . ':' . addslashes($data['transponInfo']['content']);
						    }else{
						   </php>//@{$data.uid|getUserName}:{$data.content|addslashes}<php>
							}</php> [原文地址：{:getShortUrl(U('group/Group/detail',array('gid'=>$data['gid'], 'id'=>$data['weibo_id'])))} ]';
	var mygroup_content = '<php>if($data['transponInfo']){
						   </php>//@{$data.uid|getUserName}:{$data.content|addslashes}<php>
						   	}</php> [原文地址：{:getShortUrl(U('group/Group/detail',array('gid'=>$data['gid'], 'id'=>$data['weibo_id'])))} ]';
	var $transpond_content = $('#transpond_content_<?php echo $data['weibo_id']; ?>');
	var $transpond_form = $('#transpondForm');
	var $tab_myweibo = $('#group_share_weibo .tab_myweibo');
	var $tab_mygroup = $('#group_share_weibo .tab_mygroup');
	if (tab_name == 'tab_myweibo') {
		$transpond_content.val(myweibo_content);
		$transpond_form.attr('action', '{:U('home/Widget/doShare')}');
		$tab_mygroup.css('display', 'none');
		$tab_myweibo.css('display', 'block');
	} else if (tab_name == 'tab_mygroup') {
		$transpond_content.val(mygroup_content);
		$transpond_form.attr('action', '{:U('group/WeiboOperate/transpond')}');
		$tab_myweibo.css('display', 'none');
		$tab_mygroup.css('display', 'block');
	}
};*/

//检测输入字符数
function checkTranspondLength(obj,num){
	var $transpond_button = $('#transpond_button');
	var $transpond_count  = $('#transpond_count');
	var str = $(obj).val();
	var len = getLength(str, true);
	if(len==0){
		$transpond_button.attr('disabled',true);
		$transpond_button.attr('class','btn_b_disable');
		$transpond_count.html('你还可以输入'+ (num-len) + '字');
	}else if( len > num ){
		$transpond_button.attr('disabled',true);
		$transpond_button.attr('class','btn_b_disable');
		$transpond_count.css('color','red');
		$transpond_count.html('已超出'+ (len-num) +'字');
		//textareaStatus('off');
	}else if( len <= num ){
		$transpond_button.removeAttr('disabled');
		$transpond_button.attr('class','btn_b');
		$transpond_count.css('color','#008800');
		$transpond_count.html('你还可以输入'+ (num-len) + '字');
	}
}

	function dotranspond(o){
		var options = {
			success:function(txt){
				if( txt ){
					//weibo.upCount('weibo');
					ui.success('分享成功');
				}else{
					ui.error('分享失败');
				}
			  ui.box.close();
			}
		};
		var $transpond_button = $('#transpond_button');
		$transpond_button.val('转发中...');
		$transpond_button.attr('disabled', 'true');
		$("#transpondForm").ajaxSubmit( options );
	}
</script>